<template>
  <view class="im-index">
    <view class="top">
      <u--image mode="aspectFit" class="t-image"
                src="https://yanglelelele.vip/myblog/small/im/%E5%8F%91%E6%B6%88%E6%81%AF.png">

      </u--image>
    </view>
    <view class="bottom">
      <view class="l-button">
        <u-button type="primary" text="好友" @click="navigateTo"></u-button>

      </view>
      <view class="r-button">
        <u-button type="warning " text="聊天室"></u-button>

      </view>
    </view>
  </view>
</template>
<script setup>
//引入mqtt
import * as mqtt from "mqtt/dist/mqtt.min";
import {onMounted} from "vue";
//导入配置
import mqttConfig from "@/config/mqttConfig";
//引入UUid
//建立连接
onMounted(() => {
  const client = mqtt.connect(mqttConfig.url, {
    clean: true,
    connectTimeout: 4000,
    clientId: uni.$u.guid(),
    username: mqttConfig.userName,
    password: mqttConfig.password
  });
  uni.showLoading({
    title: '加载中'
  });
  client.on("connect", () => {
    uni.hideLoading()
    uni.showToast({
      title: '连接成功',
      icon: 'success',
      duration: 500
    });

  });
  setTimeout(() => {
    //关闭连接
    client.end();
    uni.showToast({
      title: '已关闭',
      icon: 'success',
      duration: 500
    });
  }, 2000);
})
const navigateTo = () => {
  uni.navigateTo({
    url: '/pages/im/friendsList/index'
  })
}
</script>
<style lang="scss">
.im-index {
  width: 100vw;
  height: 100vh;
  background-color: #ffffff;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;

  .top {
    width: 100%;
    height: 50%;
    display: flex;
    justify-content: center;
    align-items: flex-end;

    .t-image {
    }
  }

  .bottom {
    height: 50%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 60px;


    .l-button {
      width: 100px;
    }

    .r-button {
      width: 100px;
    }
  }
}
</style>